<template>
    <view class="taskDetails">
        <!-- 主要内容 -->
        <view class="customer-content">
            <u--form labelPosition="left" :model="detailsData" :rules="rules" ref="uForm" labelWidth="70">
                <u-form-item class="item-box" label="商品类型" required prop="commodityType"
                				    @click="showSelect('commodityType')" borderBottom ref="item1">
                				    <view class="item-temp-box">
                				        <view :class="!detailsData.commodityType ? 'item-temp-text-empty' : ''">{{
                				            bus_product_type[detailsData.commodityType] || '点击选择' }}</view>
                				    </view>
                				    <u-icon slot="right" name="arrow-right"></u-icon>
                </u-form-item>
				<u-form-item class="item-box" label="商品名称:" required borderBottom ref="item1">
                    <u--input v-model="detailsData.commodityName" border="none" placeholder="请填写"></u--input>
                </u-form-item>
				<u-form-item class="item-box" label="商品编码:" required borderBottom ref="item1">
				    <u--input v-model="detailsData.commodityCode" border="none" placeholder="请填写"></u--input>
				</u-form-item>
				<u-form-item class="item-box" label="最小单位:" required borderBottom ref="item1">
				    <u--input v-model="detailsData.minUnit" border="none" placeholder="请填写"></u--input>
				</u-form-item>
				<u-form-item class="item-box" label="单位含量:" required borderBottom ref="item1">
				    <u--input v-model="detailsData.unitContent" border="none" placeholder="请填写"></u--input>
				</u-form-item>
				<!-- <u-form-item class="item-box" label="商品规格" required prop="specificationId"
								    @click="showSelect('specificationId')" borderBottom ref="item1">
								    <view class="item-temp-box">
								        <view :class="!detailsData.specificationId ? 'item-temp-text-empty' : ''">{{
								            bus_product_specification_unit[detailsData.specificationId] || '点击选择' }}</view>
								    </view>
								    <u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item> -->
				<u-form-item class="item-box" label="商品规格:" required borderBottom ref="item1">
				    <u--input v-model="detailsData.specificationId" border="none" placeholder="请填写"></u--input>
				</u-form-item>
				<u-form-item class="item-box" label="每件数量:" required borderBottom ref="item1">
				    <u--input v-model="detailsData.caseQuantity"border="none" placeholder="请填写"></u--input>
				</u-form-item>
				<u-form-item class="item-box" label="单价:" required borderBottom ref="item1">
				    <u--input v-model="detailsData.boxConversionUnitPrice" border="none" placeholder="请填写"></u--input>
				</u-form-item>
				<u-form-item class="item-box" label="箱价:" required borderBottom ref="item1">
				    <u--input v-model="detailsData.caseUnitPrice" border="none" placeholder="请填写" input-type='digit'></u--input>
				</u-form-item>
				<u-form-item class="item-box" label="拆箱价:" required borderBottom ref="item1">
				    <u--input v-model="detailsData.onlineUnitPrice" border="none" placeholder="请填写"></u--input>
				</u-form-item>
				<u-form-item class="item-box" label="吨价:" required borderBottom ref="item1">
				    <u--input v-model="detailsData.tonPrice" border="none" placeholder="请填写"></u--input>
				</u-form-item>
				<u-form-item class="item-box" label="折吨价:" required borderBottom ref="item1">
				    <u--input v-model="detailsData.tonConversionUnitPrice" border="none" placeholder="请填写"></u--input>
				</u-form-item>
				<u-form-item class="item-box" label="提成系数:" required borderBottom ref="item1">
				    <u--input v-model="detailsData.commission" border="none" placeholder="请填写"></u--input>
				</u-form-item>
				<u-form-item class="item-box" label="启用状态" required borderBottom ref="item1">
					<switch  :checked="detailsData.status==='0'?true:false" @change="change" id="swith"></switch>
				</u-form-item>
            </u--form>
        </view>
        <!-- 底部 -->
        <view class="bottom-box">
            <template>
                <view class="row-box"@click="addHandle()">
                    <u-icon name="edit-pen-fill" color="#0C1019" size="22"></u-icon>
                    <text>新增商品</text>
                </view>
            </template>
        </view>
		<u-action-sheet :show="showActionSheet" :actions="actions" title="请选择" @close="showActionSheet = false"
		    @select="selectSelect">
		</u-action-sheet>
    </view>
</template>

<script>
import { convertToDict } from '@/common/utils'
export default {
    data() {
        return {
			showActionSheet: false,
            title: '',
            current: 0,
            detailsData: {
				commodityType:null,
				minUnit:null,
				unit_content:null,
				specificationId:null,
				commodityName:null,
				unitContent:null,
				commodityCode:null,
				caseQuantity:null,
				caseUnitPrice:null,
				boxConversionUnitPrice:null,
				onlineUnitPrice:null,
				tonPrice:null,
				tonConversionUnitPrice:null,
				commission:null,
				status:'0',
				isPackage:false,
				contentUnit:'1004',
				productName:'线上产品专用',
				productId:'1889479644742111233',
				commodityPublic:'0',
				channel_type:'1001',
				classifyId:'1864132861811888130'
			},
            show:false,
            id: null,
			// 弹出底部弹出菜单，展示的集合
			actions: [],
			classTypeList:[],
			contentUnitList:[],
			rules: {
                'commodityType': {
                    type: 'string',
                    required: true,
                    message: '请选择商品类型',
                    trigger: ['blur', 'change']
                },
                'specificationId': {
                    type: 'string',
                    required: true,
                    message: '请选择商品规格',
                    trigger: ['blur', 'change']
                },
                'opportunityChannel': {
                    type: 'string',
                    required: true,
                    message: '请选择客户来源',
                    trigger: ['blur', 'change']
                },
                'businessManagerId': {
                    type: 'string',
                    required: true,
                    message: '请选择业务员',
                    trigger: ['blur', 'change']
                },
            },
        }
    },
    onLoad(options) {
        this.classTypeList = JSON.parse(uni.getStorageSync('bus_product_type'))
        this.bus_product_type = convertToDict(this.classTypeList)
		this.contentUnitList = JSON.parse(uni.getStorageSync('bus_product_specification_unit'))
		this.bus_product_specification_unit = convertToDict(this.contentUnitList)
    },
    methods: {
		change(ischecked){
			console.log(ischecked);
			this.detailsData.status = ischecked["detail"].value?0:1;
			console.log(this.detailsData.status);
		},
		addHandle() {
			this.detailsData.boxConversionUnitPrice = (this.detailsData.caseUnitPrice/this.detailsData.caseQuantity).toFixed(2);
			let obj = JSON.parse(JSON.stringify(this.detailsData))
			this.$http.post('/app/goods/add', obj).then(res => {
			    let data = res.data
			    if (data.code == 200) {
			        uni.showToast({ title: '成功', duration: 1000 });
			        setTimeout(() => {
			            uni.navigateBack()
			        }, 1000)
			    } 
			})
		},
        openPopup() {
            this.$refs.popup.open()
        },
        getColor(state) {
            let color;
            switch (state) {
                case '1001':
                color = 'rgba(0, 186, 173, 1)';
                break;
                case '1002':
                color = 'rgba(255, 141, 26, 1)';
                break;
                default:
                color = 'rgba(255, 0, 28, 1)';
            }
            return color;
        },
		// 显示选择器
		showSelect(propName) {
		    // 客户类型
		    if (propName == 'commodityType') {
		        this.actions = this.classTypeList
		    } else if (propName == 'specificationId') {
		        this.actions = this.contentUnitList
		    } else if (propName == 'opportunityChannel') {
		        this.actions = this.sourceList
		    } else if (propName == 'reminderMethod') {
		        this.actions = this.taskList
		    } else if (propName == 'reminderType') {
		        this.actions = this.remindList
		    }
		    this.tempPropName = propName
		    this.showActionSheet = true
		},
		selectSelect(e) {
            // console.log(e)
            // this.params[this.tempPropName + 'Name'] = e.name
            this.detailsData[this.tempPropName] = e.dictValue
        },
		previewImg(index) {
		    uni.previewImage({
		        current: index,
		        urls: this.detailsData.paymentScreenshot
		    })
		},
        close() {
            this.show = false
        },
        backHandle() {
            uni.navigateBack()
        }
    }
}
</script>

<style lang="scss" scoped>
/deep/.uni-navbar__header-btns-right {
    width: 64px !important;
}

.taskDetails {
    padding-bottom: 150rpx;
}

.taskDetails-content {
    margin: 20rpx 0;

    .customer-info {
        border-radius: 24rpx;
        background: rgba(255, 255, 255, 1);
        padding: 32rpx 0;
        .order-num {
            padding: 0 32rpx;
            margin-bottom: 20rpx;
            font-size: 28rpx;
            font-weight: 400;
            color: rgba(103, 117, 133, 1);
        }

        .customer-row-title {
            padding: 0 32rpx;
            text-align: center;
            // 超出隐藏
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
        }

        .customer-row {
            display: flex;
            justify-content: space-between;
            text-align: center;

            .item {
                flex: 1;

                > :nth-child(1) {
                    font-size: 28rpx;
                    font-weight: 400;
                    color: rgba(103, 117, 133, 1);
                    margin-bottom: 8rpx;
                }

                > :nth-child(2) {
                    font-size: 28rpx;
                    font-weight: 500;
                    color: rgba(12, 16, 25, 1);
                }
            }
        }
    }

    .item-title {
        padding: 48rpx 32rpx 20rpx 32rpx;
        font-size: 32rpx;
        font-weight: 500;
        color: rgba(12, 16, 25, 1);
    }

    .item-content {
        background: rgba(255, 255, 255, 1);
        padding: 0 32rpx;
        border-radius: 24rpx;

        .item-content-row {
            display: flex;
            justify-content: space-between;
            padding: 26rpx 0;
            font-size: 28rpx;
            border-bottom: 2rpx solid rgba(240, 240, 240, 1);

            >view:nth-child(1) {
                font-weight: 400;
                color: rgba(103, 117, 133, 1);
                width: 140rpx;
            }

            >view:nth-child(2) {
                flex: 1;
                font-weight: 500;
                color: rgba(12, 16, 25, 1);
                // 超出隐藏显示省略号
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
                text-align: right;
            }
        }
    }
}
.img_list {
	margin-top: 16rpx;
    display: flex;
    flex-wrap: wrap;
    .img_box {
        width: 164rpx;
        height: 164rpx;
        position: relative;
    }
    > view {
        margin-right: 20rpx;
		margin-bottom: 20rpx;
    }
}
.bottom-box {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-around;
    background: rgba(255, 255, 255, 1);
    box-shadow: 0px 0px 12rpx rgba(0, 0, 0, 0.1);
    > view {
        padding: 32rpx 0
    }

    .row-box {
        display: flex;
        align-items: center;
    }
    .column-box {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }
    text {
        font-size: 28rpx;
        font-weight: 500;
        color: rgba(12, 16, 25, 1);
        margin-left: 8rpx;
    }

}

.popup-box {
    padding: 32rpx 0;

    .popup-header {
        display: flex;
        justify-content: center;
        margin-bottom: 32rpx;
    }

    .icon-box {
        border-radius: 16rpx;
        background: #F2F2F2;
        width: 100rpx;
        height: 100rpx;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .grid-text {
        margin-top: 24rpx;
        margin-bottom: 32rpx;
        font-size: 28rpx;
    }
}
</style>